<extend name="Layout:layout_edit" />
<block name="body_content_block">
    <form action="{:AddonU('Music/item_save')}" method="post" enctype="multipart/form-data" data-success-fn="show_reload_tip()">
        <table>
            <if condition="$isSuperAdmin">
                <tr>
                    <th>租户ID：</th><td>
                        <select name="siteID" title="请选择租户" required data-url="{:AddonU('Admin/get_admin_json')}"></select>
                    </td></tr>
                <else/>
                <input type="hidden" name="siteID" value="{$loginData.siteID}"/>
            </if>
            <tr>
                <th>语音类型：</th><td>
                    <input type="radio" name="type" value="moh" checked="checked" required/>队列等待音
                    <input type="radio" name="type" value="sounds" required/>业务应用语音
                </td></tr>
            <tr>
                <th>目录名称：</th><td>
                    <select id="dirs" style="display: none;" data-url="{:AddonU('Music/get_subdir_json')}"></select>
                    <input type="text" class="easyui-textbox" name="dirName" placeholder="目录名称" title="请填写目录名称!" size="9"/>
                </td></tr>
            <tr>
                <th>选择文件：</th><td>
                    <input type="file" name="fileUrl" title="请选择语音文件!" required/>
                    <div id="file-tip" style='color:#F00;'>等待音只支持mp3、wav格式(16k,16bit,建议用格式工厂直接转wav),文件名必须是英文!</div>
                </td></tr>
            <tr id="vol">
                <th>音量调整：</th><td>
                    <select name="volume">
                        <option value="1.50">Volume 150%</option>
                        <option value="1.25">Volume 125%</option>
                        <option value="" selected>Volume 100%</option>
                        <option value=".75">Volume 75%</option>
                        <option value=".5">Volume 50%</option>
                        <option value=".25">Volume 25%</option>
                        <option value=".1">Volume 10%</option>
                    </select>
                </td></tr>
        </table>
        <input type='hidden' name='id' value='{$data.id}'/>
    </form>
</block>
<block name="body_after_block">
    <script type="text/javascript">
        item_form.resize_owner_dialog({width: 350});
        ajax_load_options({selector: 'select[name="siteID"]', def_option: '选择租户', func: afterSiteID});
        afterSiteID();
        function afterSiteID() {
            var val = $('select[name="siteID"]').val();
            if (!val) {
                val = '{$loginData.siteID}';
            }
            ajax_load_options({selector: '#dirs', queryParams: {"type": "moh", "siteID": val}, def_option: '请选择子目录'});
        }
        $('select[name="siteID"]').change(function () {
            afterSiteID();
        })
        $('input[name="type"]').change(function () {
            var v = $(this).val();
            // 其他语音只支持g729、mp3、wav格式,文件名必须是英文!
            $('#file-tip').html(v == 'moh' ? '等待音只支持mp3、wav格式,文件名必须是英文且不能有特殊字符或空格!' : '文件格式是wav,16位,单声道,8K采样率,文件名必须是英文且不能有特殊字符或空格!');

            var val = $('select[name="siteID"]').val();
            if (!val) {
                val = '{$loginData.siteID}';
            }
            if (v == 'sounds') {
                $('#dirs').show();
                ajax_load_options({selector: '#dirs', queryParams: {"type": v, "siteID": val}, def_option: '请选择子目录'});
            } else {
                $('#dirs').hide();
            }
        })

        $('#dirs').change(function () {
            var v = $(this).val();
            $(this).next().val(v);
        })
    </script>
</block>